package com.ds.lens.collector.receive;


import com.ds.lens.collector.receive.config.CollectorConfig;
import com.ds.lens.collector.receive.handler.HandlerFactory;
import com.ds.lens.collector.receive.receiver.DataReceiver;
import com.ds.lens.collector.receive.receiver.http.HTTPReceiver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.annotation.EnableKafka;

import javax.annotation.PreDestroy;

/**
 * @author ethan
 */
@EnableKafka
@Configuration
public class CollectorConfiguration {

    private HTTPReceiver httpReceiver;

    @Bean
    public DataReceiver initReceiver(HandlerFactory handlerFactory, CollectorConfig collectorConfig) {
        this.httpReceiver = new HTTPReceiver(handlerFactory, collectorConfig);
        this.httpReceiver.start();
        return this.httpReceiver;
    }

    @PreDestroy
    public void distoryServer() {
        this.httpReceiver.shutdown();
    }

}
